﻿<link href="/SiteUI/Sale/share.css" rel="stylesheet" />
<link href="/SiteUI/Sale/wgNewOrder.css" rel="stylesheet" />

<!--新收到的还没确认的订单-->
<div class="col-lg-12" id="sal-dept-wgNewOrder">
    <div class="row">
        <div class="col-lg-12 head">
            <h4><i class="icon-dashboard"></i>销售-新订单<span id="sal-dept-tipCount">(-)</span></h4>
            <a class="Lite" href="/Sale/Orders">查看全部订单>></a>
        </div>
        <div class="col-lg-12" id="sal-dept-lstNewOrder">

        </div>
        <div id="ListPaging"></div>
    </div>
</div>
<!--待确认新订单列表项模板-->
<script class="tpl-dept-NewSalOrder" type="text/html" style="display:none">
    <div class="row noItem" objid="{{d.idstr}}">
        <div class="col-lg-1 no-row-head">
            <img src='{{d.client_logo}}' />  <!--买方Logo-->
        </div>
        <div class="col-lg-11 no-row-body">
            <div class="row no-headline">
                <div class="col-lg-4 no-tradeno">
                    <span>交易编号：</span><span>{{d.idstr}}</span>
                </div>
                <div class="col-lg-5 no-client">
                    <span class="Company {{(d.client_realname)?'certificated':'no-certificated'}}"><i class="soicon icon-004office"></i>&nbsp;{{d.client_realname||d.invoiceheading}}</span>
                </div>
                <div class="col-lg-3 no-lnks">
                    {{#if (d.status=='Active'){ }}
                    <a class="LinkTo lnkDelivery" target="_blank" href=""><i class="soicon icon-localshipping"></i>安排发货</a>
                    {{#} }}
                    <a class="LinkTo" target="_blank" href="/Trade/OrderDetail?oid={{d.idstr}}">查看详情>></a>
                </div>
            </div>
            <div class="row no-describe">
                <div class="col-lg-4">
                    <span>客户订单：</span><span>{{d.src_orderserial}}[{{d.src_orderversion||'-'}}]</span>
                    <br />
                    <span>订货日期：</span><span>{{d.orderdate}}</span>
                    <br />
                    <span>采购经办：</span><a class="People {{d.buyer_id?'certificated':'no-certificated'}}"><img src="{{d.buyer_headimg}}" />{{d.buyer||d.src_buyer}}</a>
                    <br />
                </div>
                <div class="col-lg-4 withLeftIndent">
                    <span>订单金额：</span><span><strong>{{d.amountStr}}</strong></span>
                    <br />
                    {{#if (d.urgent==true){ }}
                    <span>交货日期：</span><span class="urgent" title="交货日期已临近，请注意跟进">{{d.deliverydate}}<i class="icon-erroroutline"></i></span>
                    {{#}else{ }}
                    <span>交货日期：</span><span>{{d.deliverydate}}</span>
                    {{#} }}
                    <br />
                    <span>销售经办：</span><a class="People {{d.saler_id?'certificated':'no-certificated'}}" objid="{{d.saler_id}}"><img src='{{d.saler_headimg}}' />{{d.saler||d.src_saler}}</a>
                </div>
            </div>
        </div>
    </div>
</script>

<script src="/LiberUI/Scripts/laytpl.js"></script>
<script>
    wgNewSalOrder = {
        newOrders: [],
        tplNewOrder: null,
        lstNewOrders: null,
        cnd:{
            onlymine:false,
            status:'pending',
            page:1,
            num:5
        },
        query: function (recount) {
            wgNewSalOrder.lstNewOrders.vl(null)
                                      .update();
            if (User.DataRange.onlymine == false && User.Authority.findObj("auth","Sale|Order|Admin") == null) {
                wgNewSalOrder.lstNewOrders.Empty("抱歉，您没有查看部门订单的权限")
                                          .update();
                wgNewSalOrder.ListPaging.hide();
            }
            else {
                if (recount) {
                    $.getJSON("/Sale/CountOrders", wgNewSalOrder.cnd, wgNewSalOrder.onCountEnd);
                }
                wgNewSalOrder.lstNewOrders.Loading("正在努力加载...");
                $.getJSON("/Sale/QueryOrders", wgNewSalOrder.cnd, wgNewSalOrder.onGetNewOrdersEnd);      
            }
        },
        makeOrderView: function ($item, od) {
            od.client_logo =od.client_logo||"/UserFile/DefaultCompanyLogo.gif";
            od.client = od.client_realname || od.invoiceheading;
            od.buyer = od.buyer || od.src_buyer;
            od.consignee_displayname = od.src_consignee || od.consignee_realname;
            od.orderdate = new Date(od.src_orderdate || od.createtime).toString();
            od.deliverydate = new Date(od.src_deliverydate || od.deliverydate).toString();
            od.urgent = daysBetween(new Date(od.src_deliverydate || od.deliverydate).toString(), new Date().toString())<5;
            od.amountStr = od.amount.roundTo(2).toThousands();
            od.taxrate = od.taxrate + "%";
            od.dlvPercent = od.totaldelivery ? ('<em>[' + (od.totaldelivery / od.amount).formatPercent(2) + ']</em>') : '';
            od.stockinPercent = od.totalstockin ? ('<em>[' + (od.totalstockin / od.amount).formatPercent(2) + ']</em>') : '';

            var v = wgNewSalOrder.tplNewOrder.render(od);
            if (od.status == 'Pending' && od.src_orderversion && od.src_orderversion.split('-')[1] != '01') {
                $(v).addClass("withHistory");
            }
            $item.append($(v).addClass("fladeInUp"));          
        },
        onGetNewOrdersEnd: function (rtn) {
            if (rtn.IsPositive) {
                wgNewSalOrder.lstNewOrders.vl(rtn.Data["Orders"])
                                          .Empty("没有符合条件的记录")
                                          .update();
            }
            else {
                wgNewSalOrder.lstNewOrders.Empty(ErrFormat(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error));
            }
        },
        GoPage: function (page) {
            wgNewSalOrder.page = page;
            wgNewSalOrder.query();
        },
        onCountEnd: function (rtn) {
            if (rtn.IsPositive) {
                $("#sal-dept-tipCount").vl("(" + rtn.Data["Total"] + ")");
                //分页控件
                wgNewSalOrder.ListPaging.option("Total", rtn.Data["Total"])
                                        .option("CurrPage", 1)
                                        .update();
            }
        }
    }
    $(function () {
        wgNewSalOrder.tplNewOrder = laytpl($(".tpl-dept-NewSalOrder")[0].innerHTML);  //定义模板实例
        wgNewSalOrder.lstNewOrders = new LiberUI.Lister("#sal-dept-lstNewOrder")
                                             .option("Slctble", false)
                                             .option("ContentRender", wgNewSalOrder.makeOrderView)
                                             .Loading("正在加载...");

        wgNewSalOrder.ListPaging = new LiberUI.Paging("#ListPaging")
                                              .option("Row", 5);
                                         
        if (User) {
            wgNewSalOrder.query(true);
        }
        else {
            $("body").on("UserReady", function () { wgNewSalOrder.query(true); });
        }
        $("body").on("DataRangeChanged", function () { wgNewSalOrder.query(true); });
    })
</script>
